package com.zy.common;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author CarreyZhou
 * @Date: 2024/5/3 11:24
 */
@Data
public class ApiResult<T> implements Serializable {
    private static final long serialVersionUID = -8609261033217837993L;

    private int code;

    private String message;

    private boolean success;

    private T data;


    public static <T> ApiResult<T> success(T data, String message) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(200);
        apiResult.setSuccess(true);
        apiResult.setMessage(message);
        apiResult.setData(data);
        return apiResult;
    }

    public static <T> ApiResult<T> success(T data) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(200);
        apiResult.setSuccess(true);
        apiResult.setData(data);
        return apiResult;
    }

    public static <T> ApiResult<T> success(String message) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(200);
        apiResult.setSuccess(true);
        apiResult.setMessage(message);
        return apiResult;
    }

    public static <T> ApiResult<T> error(int code, String message) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(code);
        apiResult.setSuccess(false);
        apiResult.setMessage(message);
        return apiResult;
    }
}
